<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo google_maps_key(); ?>" type="text/javascript"></script>

<div id="map_<?php echo $block_instance['data']->id; ?>" class="map_<?php echo $block_instance['data']->size_mode; ?>">
</div>

<?php if ((!$content->geo_lat ||
		  !$content->geo_lon)
		  && strlen($this->Content_model->geocodable_address($content))): ?>
<script type="text/javascript" charset="utf-8">
	// need to geocode the address
	var gc = new GClientGeocoder().getLatLng(
		"<?php echo form_prep($this->Content_model->geocodable_address($content)) ?>",
		function(point)
		{
			if (point == null || !point)
			{
			}
			else
			{
				$.post('/bricabox/<?php echo $bricabox->id; ?>/save_geocode_data', {content_id: <?php echo $content->id; ?>, lat: point.lat(), lng: point.lng()});
			
				// draw the marker
				MapMayhem.init(<?php echo $block_instance['data']->id; ?>);
				var marker_for_<?php echo $content->id; ?> = MapMayhem.addMarker(
					'<?php echo $this->Content_model->geocodable_address($content); ?>',
					<?php echo $content->id; ?>,
					'<?php echo form_prep($content->field1_value); ?>',
					point.lat(),
					point.lng(),
					true
				);
			}
		}
	);
</script>
<?php else: ?>
<script type="text/javascript" charset="utf-8">
	// already have lat/lon pair
	MapMayhem.init(<?php echo $block_instance['data']->id; ?>);
	var marker_for_<?php echo $content->id; ?> = MapMayhem.addMarker(
		'<?php echo $this->Content_model->geocodable_address($content); ?>',
		<?php echo $content->id; ?>,
		'<?php echo form_prep($content->field1_value); ?>',
		<?php echo $content->geo_lat; ?>,
		<?php echo $content->geo_lon; ?>,
		true
	);
</script>
<?php endif; ?>